Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 2 - AppleScript Language Reference
Chapter 8 - Handlers / Command Handlers for Script Applications


Open Handlers

All applications that are compatible with System 7 can respond to the Open command, even if they aren't scriptable. The Finder sends an Open command to an application whenever the user drags file, folder, or disk icons over the application's icon and releases the mouse button. The Open command is sent even if the application is already running.

Like any other application, a script application receives an Open command whenever the user drags file, folder, or disk icons over the application's icon. If the script in the script application includes an Open handler, the statements within the handler run when the application receives the Open command. The Open handler takes a single parameter; when the handler is called, the value of that parameter is a list of all the items whose icons were dropped on the script application's icon. (Each item in the list is an alias; you can convert it to a pathname by using as string.)

For example, this Open handler makes a list of the pathnames for all items dropped on the script application's icon:

on open names
   tell application "Scriptable Text Editor"      make new window
      repeat with i in names
         set iPath to (i as string)
         set selection to iPath & return
      end repeat
      save front window in file "List of Files"   end tell
end open
Files, folders, or disks are not moved, copied, or affected in any way when their icons are dragged and dropped over a script application's icon. The Finder just gets a list of their identities and sends that list to the script application as the direct parameter of the Open event. Of course, the script in the script application could easily tell the Finder to move, copy, or otherwise manipulate them.

Note
Due to a known limitation of system software, you can't drop icons on an icon for a script application that's stored on a floppy disk.
You can also run an Open handler by sending a script application the Open command. For details, see "Calling a Script Application" on page 251.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996